/*
Copyright (c) 2007-2009, Yusuke Yamamoto
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
 * Neither the name of the Yusuke Yamamoto nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.wangyi.sdk;

import android.content.Context;

import com.wangyi.activity.R;

/**
 * @author Yusuke Yamamoto - yusuke at mac.com
 * 
 *         modified by gcwang
 */
public class Configuration {

	private static Configuration configuration;
	private final Context context;

	private Configuration(Context context) {
		this.context = context;
	}

	public static Configuration getInstance(Context context) {
		if (configuration == null) {
			configuration = new Configuration(context);
		}
		return configuration;
	}

	/* 从sdk.xml取得相关配置 */
	public String getStringProperty(int keyname) {
		String value = context.getResources().getString(keyname);
		return value != null && !"".equals(value) ? value : "";
	}

	/**
	 * get clientVersion
	 * 
	 * @param clientVersion_id
	 * @return
	 */
	public String getCilentVersion() {
		return getStringProperty(R.string.sdk_clientVersion);
	}

	/**
	 * get ProxyHost
	 * 
	 * @param proxyHost_id
	 * @return
	 */
	public String getProxyHost() {
		return getStringProperty(R.string.sdk_proxyHost);
	}

	public String getProxyUser() {
		return getStringProperty(R.string.sdk_proxyUser);
	}

	public String getClientURL() {
		return getStringProperty(R.string.sdk_clientURL);
	}

	public String getProxyPassword() {
		return getStringProperty(R.string.sdk_proxyPassword);
	}

	public int getProxyPort() {
		return getIntProperty(R.string.sdk_proxyPort);
	}

	public int getConnectionTimeout() {
		return getIntProperty(R.string.sdk_http_connectionTimeout);
	}

	public int getReadTimeout() {
		return getIntProperty(R.string.sdk_http_readTimeout);
	}

	public int getRetryCount() {
		return getIntProperty(R.string.sdk_http_retryCount);
	}

	public int getRetryIntervalSecs() {
		return getIntProperty(R.string.sdk_http_retryIntervalSecs);
	}

	public String getUser() {
		return getStringProperty(R.string.sdk_userId);
	}

	public String getPassword() {
		return getStringProperty(R.string.sdk_password);
	}

	public String getUserAgent() {
		return getStringProperty(R.string.sdk_userAgent);
	}

	public String getOAuthConsumerKey() {
		return getStringProperty(R.string.sdk_Consumer_Key);
	}

	public String getOAuthConsumerSecret() {
		return getStringProperty(R.string.sdk_Consumer_Secret);
	}

	public boolean getBooleanProperty(int id) {
		String value = getStringProperty(id);
		try {
			return Boolean.valueOf(value);
		} catch (NumberFormatException nfe) {
			return false;
		}
	}

	public int getIntProperty(int id) {
		String value = getStringProperty(id);
		try {
			return Integer.parseInt(value);
		} catch (NumberFormatException nfe) {
			return -1;
		}
	}

	public long getLongProperty(int id) {
		String value = getStringProperty(id);
		try {
			return Long.parseLong(value);
		} catch (NumberFormatException nfe) {
			return -1;
		}
	}

	public int getNumberOfAsyncThreads() {
		return getIntProperty(R.string.sdk_async_numThreads);
	}

	public boolean getDebug() {
		return getBooleanProperty(R.string.sdk_debug);
	}
	
	public String getRedirectUri(){
		return getStringProperty(R.string.sdk_redirecturi);
	}
}
